package com.example.springboot.controller;

import com.example.springboot.model.Email;
import com.example.springboot.service.EmailService;
import com.example.springboot.util.EmailUtil;
import com.example.springboot.util.ResponseUtil;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmailController {
    @Autowired private EmailService emailService;

    /**
     * 邮件分页
     * @param email
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/email/list")
    public String list(Email email, @RequestParam(defaultValue = "0") Integer pageNum,@RequestParam(defaultValue = "10" ) Integer pageSize){
        Page<List<Email>> page =emailService.getListPage(email,pageNum,pageSize);
       return ResponseUtil.getSuccess(page.getResult(),page.getTotal());
    }

    /**
     * 发送邮件方法
     * @param email
     * @return
     */
    @RequestMapping("/email/send")
    public String send(Email email){
        emailService.sendEmail(email);
        return ResponseUtil.getSuccess();
    }

    /**
     * 收邮件
     * @return
     */
    @RequestMapping("/email/revice")
    public String revice(){
        EmailUtil.revice();
        return ResponseUtil.getSuccess();
    }
}
